import react from '@vitejs/plugin-react';
import { resolve } from 'path';
import { defineConfig } from 'vite';
import path from 'path';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  // base: process.env.NODE_ENV === 'production' ? './' : '/',
  base: './',
  build: {
    rollupOptions: {
      output: {
        format: 'iife',
        entryFileNames: '[name].js', // 修改入口文件名格式
        chunkFileNames: '[name].js', // 修改代码块文件名格式
        assetFileNames: '[name].[ext]' // 修改静态资源文件名格式
      },
    },
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
    },
  },
  css: {
    modules: {
      localsConvention: 'camelCase',
    },
    preprocessorOptions: {
      less: {
        additionalData: `@import "./src/global.less";`
      }
    }
  },
  server: {
    host: '0.0.0.0',
    port: 5000, // 根据需求设置端口号
    open: true,
    proxy: {
      '/api': {
        target: 'http://localhost:8000',
        rewrite: (path) => path.replace(/^\/api/, ''),
        changeOrigin: true,
      },
    },
  },
});
